﻿using System;

namespace Borg
{
    [Serializable]
    public class LogArgs : EventArgs
    {
        [NonSerialized]
        private readonly object _source;
        private readonly LogType _type;
        private string _message;
        private object[] _args;

        public LogType Type
        {
            get { return _type; }
        }

        public object Source
        {
            get { return _source; }
        }

        public string Message
        {
            get
            {
                if (_args != null)
                {
                    _message = string.Format(_message, _args);
                    _args = null;
                }

                return _message;
            }
        }

        public LogArgs(LogType type, object source, string message, params object[] args)
        {
            if (message == null)
                throw new ArgumentNullException("message");
            
            if (args == null)
                throw new ArgumentNullException("args");
            
            _type = type;
            _source = source;
            _message = message;
            _args = args;
        }
    }

    public delegate void LogEventHandler(LogArgs args);
}
